﻿using Microsoft.ServiceModel.Web;
using System;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Web;
using System.Web.Routing;
using Zeus.Comunicaciones.Servicios.Rest.Security;

namespace Zeus.Comunicaciones.Servicios.Rest
{
    public class Global : HttpApplication
    {
        void Application_Start(object sender, EventArgs e)
        {
            RegisterRoutes();
        }

        private void RegisterRoutes()
        {
            //RouteTable.Routes.Add(new ServiceRoute("GenericService", new WebServiceHost2Factory(), typeof(GenericService)));
            RouteTable.Routes.Add(new ServiceRoute("GenericService", new ZeusServiceFactory(), typeof(GenericService)));
            RouteTable.Routes.Add(new ServiceRoute("Acceso", new WebServiceHost2Factory(), typeof(AccesoServicio)));
        }
    }

    public class ZeusServiceFactory : ServiceHostFactory
    {
        protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
        {
            WebServiceHost2 result = new WebServiceHost2(serviceType, true, baseAddresses);

            result.Interceptors.Add(new SecurityInterceptor());

            return result;
        }
    }
}
